﻿using NAudio.Wave;
using NAudio.Wave.SampleProviders;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace AudioSourceManager
{
    public class AudioFileSource : IAudioSource
    {
        AudioFileReader audioFile;

        protected override SampleChannel GetSampleChannel()
        {
            audioFile = new AudioFileReader(AudioPath);
            SampleToWaveProvider waveProvider = new SampleToWaveProvider(audioFile);
            SampleChannel sampleChannel = new SampleChannel(waveProvider, false);
            return sampleChannel;
        }

        public override void Dispose()
        {
            throw new NotImplementedException();
        }

        public override string GetLog()
        {
            TimeSpan currentTime = audioFile.CurrentTime;
            TimeSpan totalTime = audioFile.TotalTime;
            return $"{currentTime.ToString(@"hh\:mm\:ss")}/{totalTime.ToString(@"hh\:mm\:ss")}";
        }

        public override bool TryMatch(string Path)
        {
            return Path.EndsWith(".mp3") || Path.EndsWith(".wav");
        }
    }
}
